<template>
  <div class="zjjg">
    <van-icon name="success" color="red" :style="{top:top}"  class="success"/>
    <div class="add-car" @click.stop="zjjg"></div>
  </div>
</template>
<script>
  import {Post} from "../gp.js"
  // import { Dialog } from "vant";
  export default{
    props:['item'],
    data(){
      return{
        top:"20px",
      }
    },
    methods:{
      zjjg(){
          let url = "/user/putin";
          let data = {};
          if (this.$store.state.id == "" && sessionStorage.getItem("id") == null) {
            // 验证登录状态，弹窗确认
             this.$dialog.confirm({
                title: "您未登录",
                message: `是否前往登录`,
                cancelButtonColor: "#ccc",
                confirmButtonColor: "#ee0a24",
              }).then(()=>{
                this.$router.push("/login");
              }).catch(() => {});
          } else if (sessionStorage.getItem("id")) {
            this.$store.commit("setId", sessionStorage.getItem("id"));
            this.$store.commit("setUname", sessionStorage.getItem("username"));
            this.$store.commit("setIslogin", sessionStorage.getItem("islogin"));
            this.$store.commit("setWallet", sessionStorage.getItem("wallet"));
            // obj.user_id,  obj.goods_id,  obj.price,   obj.count
            data.user_id = sessionStorage.getItem("id")*1;
            data.goods_id=this.item.gid;
            data.price=this.item.price;
            data.count=1;
            Post(url, data).then((res) => {
              console.log(res);
              this.top="-10px";
              setTimeout(()=>{
                this.top="20px";
              },2000)
              this.$toast('加购成功')
            });
        }
      }
    }
  }
</script>

<style scoped lang="scss">
.zjjg{
  width: 50px;
  height: 50px;
  // background-color:green;
  position:absolute;
  bottom:0;
  right:0;
  .success{
    position:absolute;
    // top:0;
    left:50%;
    transform:translateX(-50%);
  }
   .add-car {
        position: absolute;
        margin: 0;
        width: 2.5rem;
        height: 2.5rem;
        right: 0.375rem;
        bottom: 0.375rem;
        /* background: url("http://47.98.224.84:3000/jd_card/tubiao/addcar.png") no-repeat center center; */
        background: url("http://127.0.0.1:3000/jd_card/tubiao/addcar.png") no-repeat center center;
        background-size: 1.625rem 1.5625rem;
    }
}

</style>
